<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>平安标记</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="{{asset('/layuiadmin/layui/css/layui.css')}}" media="all">
  <link rel="stylesheet" href="{{asset('/layuiadmin/style/admin.css')}}" media="all">
  <style>
    .edit{background-color: #ed9c3a;}
    .shenhe{background-color: #429488;}    
    .see{background-color: #7cb717;} 
    .tongbu{background-color: #4c9ef8;color:#fff;}
    .cur{color:#009688;}
    .yname{font-size: 13px; color: #444;}
  </style>
</head>

<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12" style="margin-top:0px">

        <div class="layui-fluid">
          <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
              <div class="layui-card"> 
                <div class="layui-card-header">平安插件标记</div>
                <div class="layui-card-body">
                  <div class="" style="font-size:14px;">
                    <div class="layui-form layui-form-pane">
                      <div class="layui-form-item">
                        <div class="layui-inline">
                          <label class="layui-form-label yname">选择排序</label>
                          <div class="layui-input-inline">
                              <select name="agent" id="agent" lay-filter="agent" lay-search>
                                <option value="0" selected="selected">未标记</option>
                                <option value="1">使用插件</option>
                                <option value="2">未使用插件</option>
                              </select>
                          </div>
                        </div>
                        <div class="layui-inline">
                          <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="date" style="width: 200px">
                          </div>
                        </div>
                        <div class="layui-inline">
                          <button class="layui-btn layui-btn-normal" style="border-radius:5px;" id="search">确定</button>
                          <button class="layui-btn layui-btn-normal" style="border-radius: 5px;" id="export">导出</button>
                          <button class="layui-btn layui-btn-normal" style="border-radius: 5px;" id="export1">导出插件费扣款记录</button>
                        </div>
                      </div>
                    </div>
                  
                    <table class="layui-hide" id="test-table-page" lay-filter="test-table-page"></table>
                    <script type="text/html" id="table-content-list" class="layui-btn-small">
                        @{{#  if(d.type=='0'){ }}
                        <a class="layui-btn layui-btn-normal layui-btn-xs ischajian" lay-event="ischajian">使用插件</a>
                        <a class="layui-btn layui-btn-normal layui-btn-xs nochajian" lay-event="nochajian">不使用插件</a>
                        @{{#  } else if(d.type=='1') { }}
                        <a class="layui-btn layui-btn-normal layui-btn-xs">使用插件2</a>
                        @{{#  } else if(d.type=='2') { }}
                        <a class="layui-btn layui-btn-normal layui-btn-xs">不使用插件1</a>
                        @{{#  } }}
                    </script>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

      </div>
    </div>

    <script src="{{asset('/layuiadmin/layui/layui.js')}}"></script>
    <script>
      var token = localStorage.getItem("Usertoken");
      var str=location.search;
      var store_id=str.split('?')[1];

      layui.config({
          base: '../../layuiadmin/' //静态资源所在路径
      }).extend({
          index: 'lib/index' //主入口模块
      }).use(['index','form','table','laydate'], function(){
          var $ = layui.$
            ,admin = layui.admin
            ,form = layui.form
            ,table = layui.table
            ,laydate = layui.laydate;

          $('.user_id').val(store_id);
          // 未登录,跳转登录页面
          $(document).ready(function(){
            if(token==null){
              window.location.href="{{url('/user/login')}}";
            }
          });
          // 渲染表格*********
          table.render({
            elem: '#test-table-page'
            ,url: ""
            ,method: 'post'
            ,where:{
                token:token,
                type:'3',
            }
            ,request:{
                pageName: 'p',
                limitName: 'l'
            }
            ,page: true
            ,cellMinWidth: 100
            ,cols: [[

              {align:'left', field:'store_name', title: '门店名称'},
              {align:'right', field:'merchant_id', title: '平安商户号'},
              {align:'right', field:'status_name', title: '插件是否使用'},
              {width:300,align:'center', fixed: 'right', toolbar: '#table-content-list',title: '操作'}
            ]]
            ,response: {
                statusName: 'status' //数据状态的字段名称，默认：code
                ,statusCode: 1 //成功的状态码，默认：0
                ,msgName: 'message' //状态信息的字段名称，默认：msg
                ,countName: 't' //数据总数的字段名称，默认：count
                ,dataName: 'data' //数据列表的字段名称，默认：data
            }
            ,done: function(res, curr, count){
              // console.log(res);
              $('th').css({'font-weight': 'bold', 'font-size': '15','color': 'black','background':'linear-gradient(#f2f2f2,#cfcfcf)'});	//进行表头样式设置
            }
          });
        // 搜索
        table.on('tool(test-table-page)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var e = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            //          console.log(e);
            // localStorage.setItem('s_store_id', e.store_id);
    
            if(layEvent === 'ischajian'){
                $.post("{{url('/api/user/pingan_plug')}}",
                {
                    token:token
                    ,id:e.id
                    ,type:1
                },function(res){
                    if(res.status==1){
                        layer.msg(res.message, {
                        offset: '50px'
                        ,icon: 1
                        ,time: 2000
                        });
                    }else{
                        layer.msg(res.message, {
                        offset: '50px'
                        ,icon: 2
                        ,time: 2000
                        });
                    }
                },"json");
            }
    
            if(layEvent === 'nochajian'){
                $.post("{{url('/api/user/pingan_plug')}}",{token:token,id:e.id,type:2},function(res){
                    if(res.status==1){
                        layer.msg(res.message, {offset: '50px',icon: 1,time: 2000});
                        setTimeout(function () {
                            location.reload()
                        }, 2000);
                    }else{
                        layer.msg(res.message, {offset: '50px',icon: 2,time: 2000});
                        // setInterval(location.reload(),2000);
                        setTimeout(function () {
                            location.reload()
                        }, 2000);
                    }
                },"json");
            }
        });
        
        let _data = '';
        laydate.render({
          elem: '#date', //指定元素
          done: function(value, date){
            _data = value;
          }
        });
    
        // 导出平安标记
        $('#export').click(function(){
            var type = $('#agent').val();
    
            window.location.href = "{{url('/api/export/pingan_tag')}}" + "?type=" + type + "&token=" + token;
        })
        
        // 导出平安标记
        $('#export1').click(function(){
            var type = $('#agent').val();
            let _url = "{{url('/api/export/pingan_chajian')}}" + "?type=" + type + "&token=" + token;
            if (_data) {
                _url += '&date=' + _data;
            }
            window.location.href = _url;
        })
    
        $('#search').click(function(){
          var type = $('#agent').val();
          //执行重载
          table.reload('test-table-page', {
            url: "{{url('/api/user/pingan')}}",
            where: {
              type: type
            }
            ,page: {
              curr: 1 //重新从第 1 页开始
            }
          });
        });
        
    });
      
    </script>
  </div>
</body>
</html>